home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_03 / 1103101a < prev    next >
Text File  |  1993-01-03  |  1KB  |  58 lines

  1. // date8.h
  2.  
  3. // Forward declarations
  4. class istream;
  5. class ostream;
  6.  
  7. class Date
  8. {
  9.     int month;
  10.     int day;
  11.     int year;
  12.  
  13.     static int dtab[2][13];
  14.  
  15. public:
  16.     // Constructors
  17.     Date();         // Get today's date (see .cpp file)
  18.     Date(int m, int d, int y)
  19.       {month = m; day = d; year = y;}
  20.  
  21.     // Accessor Functions
  22.     int get_month() const
  23.       {return month;}
  24.     int get_day() const
  25.       {return day;}
  26.     int get_year() const
  27.       {return year;}
  28.  
  29.     Date operator-(const Date& d2) const;
  30.     Date& operator-()
  31.       {month = -month; day = -day; year = -year;
  32.        return *this;}
  33.  
  34.     int compare(const Date&) const;
  35.  
  36.     // Relational operators
  37.     int operator<(const Date& d2) const
  38.       {return compare(d2) < 0;}
  39.     int operator<=(const Date& d2) const
  40.       {return compare(d2) <= 0;}
  41.     int operator>(const Date& d2) const
  42.       {return compare(d2) > 0;}
  43.     int operator>=(const Date& d2) const
  44.       {return compare(d2) >= 0;}
  45.     int operator==(const Date& d2) const
  46.       {return compare(d2) == 0;}
  47.     int operator!=(const Date& d2) const
  48.       {return compare(d2) != 0;}
  49.  
  50.     // Stream I/O operators
  51.     friend ostream& operator<<(ostream&, const Date&);
  52.     friend istream& operator>>(istream&, Date&);
  53.  
  54.     static int isleap(int y)
  55.       {return y%4 == 0 && y%100 != 0 || y%400 == 0;}
  56. };
  57.  
  58.